#include "stdafx.h"
#include "ineedthis.h"


// Returns a MyList that is part of the form, called in wm_paint
MyList *MyForm::getList()
{
	return m_list;
}

// Return a MyEdit that is part of the form, called in wm_paint
MyEdit *MyForm::getEdit()
{
	return m_edit;
}

// Called in wm_create
void MyForm::initialize(HWND hwnd)
{
	RECT rc;		// MyList Rectangle
	TEXTMETRIC tm;	// Learn the height of text

	m_hwnd = hwnd;

	HDC hdc;		// Used in getting textmetric
	hdc = GetDC(hwnd);	// hdc needed for textmetric
	GetTextMetrics(hdc, &tm);				// textmetric gives height of font
	rc.top = 100;		// arbitratry number at the moment
	rc.bottom = rc.top + (tm.tmHeight * 10);	// Gives 10 item in height
	rc.left = 30;		// arbitrary number at the moment
	rc.right = 130;		// arbitrary width at the moment

	m_list = new MyList();		// Create a new MyList pointer
	m_list->setRect(&rc);		// Give the MyList a rectangle dimension

	RECT rcedit;						// RECT for the edit box
	memset(&rcedit, 0, sizeof(RECT));	// Memset zero the rect
	memcpy(&rcedit, &rc, sizeof(RECT));	// Copy the list rect to the edit rect

	rcedit.left = rc.right + 2;			// Make it border the list
	rcedit.bottom = 400;				// Give the edit box a good height
	rcedit.right = 400;					// Give the edit box a good width

	RECT rclast;
	rclast.top = rcedit.top + 1;
	rclast.left = rcedit.left + 1;
	rclast.right = rcedit.left + 1;
	rclast.bottom = rcedit.top + 1;

	

	m_edit = new MyEdit();		// Create memory for MyEdit pointer
	m_edit->initialize();
	m_edit->setParent(hwnd);		// Set the parent hwnd for the editbox to hwnd
	m_edit->setRect(&rcedit);	// Set rect that was created earlier for the edit box
	m_edit->setLastRect(&rclast);

	RECT rc2;
	// RC2 is going to be the rectangle for the item
	memset(&rc2, 0, sizeof(RECT));		// Memset the rc2 to zero
	memcpy(&rc2, &rc, sizeof(RECT));	// Copy the list rectangle to the item rect
	rc2.top++;							// Give a border to the rc2 top
	rc2.bottom = rc2.top + tm.tmHeight;	// Add tmHeight to the bottom	
	rc2.left++;							// Make the left one over
	
	char mystring[128];					// string to put in item
	sprintf_s(mystring, "int main()");	// contents of string
	int mystrlen = strlen(mystring);	// strring length

	MyItem *item;						// Pointer to item
	item = new MyItem();				// Create memory for pointer
	item->setRect(&rc2);				// Give item rectangle
	item->setText(mystring);			// Give item string

	m_list->addItem(item);				// Add item to list

	CreateCaret(m_hwnd, (HBITMAP)NULL, 1, 16);
	ShowCaret(m_hwnd);
}
